import { defineStore } from 'pinia'
import { profileInfo } from 'api/modules/api.personal'
import { getUserInfoApi, getAccountInfoApi } from 'api/modules/api.account'

const userInfoStore = defineStore(
    'userInfo',
    {
        state: () => ({
            personalInfo: {},
            userInfo: {},
            accountInfo: {},
        }),
        actions: {
            // 个人中心
            getProfileInfo(userInfo) {
                return new Promise((resolve, reject) => {
                    profileInfo(userInfo).then(res => {
                        this.personalInfo = res.data
                        resolve(res)
                    }).catch(error => {
                        reject(error)
                    })
                })
            },
            // 获取用户信息
            getUserInfo() {
                return new Promise((resolve, reject) => {
                    getUserInfoApi().then(res => {
                        this.userInfo = res.data
                        resolve(res)
                    }).catch(error => {
                        reject(error)
                    })
                })
            },
            // 获取账户信息
            getAccountInfo(account) {
                return new Promise((resolve, reject) => {
                    getAccountInfoApi(account).then(res => {
                        this.accountInfo = res.data
                        resolve(res)
                    }).catch(error => {
                        reject(error)
                    })
                })
            },
        }
})

export default userInfoStore


